package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.UserTest;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@Service
public class UserTestApiImpl implements UserTestApi {

    @Autowired
    private MongoTemplate mongoTemplate;


    //根据用户id查询最新的报告id
    @Override
    public UserTest findReportIdByUserId(Long userId,Integer type) {
        Query query = new Query(Criteria.where("userId").is(userId).and("passType").is(type.toString()));
        // query.with(Sort.by(Sort.Direction.DESC, "updated"));
        UserTest userTest = mongoTemplate.findOne(query, UserTest.class);
        return userTest;
    }

    @Override
    public void save(UserTest u1) {
        mongoTemplate.save(u1);
    }
}
